const app = getApp();
import { baseUrl } from "../../../api/request"
import { getStorage } from "../../../utils/localStorage";
import { getMapDistance } from "../../../utils/address"
import { infoPlace, venueCode } from "../../../api/homePage"
Page({
  data: {
    navData: {
      level: 2,
      title: '场所详情'
    },
    imgUrl: baseUrl,
    swiper: {
      autoplay: true, //自动切换
      dots: true, //指示点
      dotsColor: "#ffffff", //指示点颜色
      dotsActiveColor: "#4646A0", //选中指示点颜色
      circular: true, //衔接滑动
      duration: 3000, //滑动动画时长
      boxFlag: false,
    },
    soFlag: false,
    dltObj: {},
    latlng: getStorage("latLng"),
    user: getStorage("user"),
    navMargin: app.globalData.navHeight + app.globalData.navTop,
    venuList: [],
    type: null,
  },
  onLoad(options) {
    //判断用户是否已经登录，否则跳转到登录页重新登录
    if (!getStorage("user")) {
      wx.redirectTo({
        url: '/pages/bootPage/index',
      });
    };
    /* 获取是否是从分享页进来的参数 true时 false不是 */
    app.globalData.sheetFlag = false;
    if (options.sheet) {
      app.globalData.sheetFlag = options.sheet;
    };
    this.getInfo(options.id);
    this.getVenueCodeList(options.id)
  },
  //获取详情信息
  getInfo(id) {
    infoPlace({ venueId: id }).then(res => {
      res.data.data.imageScale = res.data.data.imageScale.split(",");
      res.data.data.distance = getMapDistance(this.data.latlng.lat, this.data.latlng.lng, res.data.data.latitude, res.data.data.longitude);
      this.setData({
        dltObj: res.data.data
      })
    });
  },
  //获取卡券列表数据
  getVenueCodeList(id) {
    venueCode({ userId: this.data.user.id, venueId: id }).then(res => {
      this.setData({
        venuList: res.data.data,
      });
    });
  },
  //查看券码
  listTap(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pagesWoDe/pages/cardRoll/index',
    })
  },
  //导航按钮点击事件
  daohangClick() {
    let that = this.data;
    wx.openLocation({
      name: that.dltObj.venueName,
      latitude: Number(that.dltObj.latitude),
      longitude: Number(that.dltObj.longitude),
    });
  },
  onShow() {
  },
  onReady() {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(res) {
    let that = this;
    return {
      title: that.data.dltObj.title,
      // imageUrl: that.data.detailObj[0],
      path: "pagesShouYe/pages/jingquDetail/index?id=" + that.data.dltObj.id + "&type=" + this.data.type + "&sheet=" + true,
      success: function (res) {
        console.log(res, "转发成功")
      },
      fail: function (res) {
        console.log(res, "转发失败")
      }
    }
  },
})